﻿using System.IO;
using System.Text;
using SIMA.Core.Extension;

namespace SIMA.Generator
{
    internal static class csGenerator
    {
        internal static void CreateModelClass(Table table, string ProjectName, string path)
        {
            string file = string.Concat(table.Name, ".cs");
            path = Path.Combine(path, ProjectName);
            string folderPath = Path.Combine(path, "Model");
            Directory.CreateDirectory(folderPath);
            using (StreamWriter streamWriter = new StreamWriter(Path.Combine(folderPath, file)))
            {
                //Generating the libraries assemblies
                streamWriter.WriteLine("using System;");
                streamWriter.WriteLine("using System.Runtime.Serialization;");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("using SIMA.Core.Attributes;");
                streamWriter.WriteLine("using SIMA.Core.Data.Validators;");
                streamWriter.WriteLine("using SIMA.Core.Data.Entity;");
                streamWriter.WriteLine();
                //Declaring the namespace
                streamWriter.WriteLine(string.Format("namespace {0}.Model", ProjectName));
                streamWriter.WriteLine("{");
                streamWriter.WriteLine("\t[Table(\"" + table.Name + "\")]");
                streamWriter.WriteLine("\t[Serializable]");
                //declaring the header of class
                streamWriter.WriteLine("\tpublic class " + table.Name + ": XmlEntity");
                streamWriter.WriteLine("\t{");

                //Creating the Fields and Properties
                CreateFieldsAndProperties(streamWriter, table);


                //ending the class
                streamWriter.WriteLine("\t}");

                //ending the namespace
                streamWriter.WriteLine("}");


            }
        }

        internal static void CreateFieldsAndProperties(StreamWriter stream, Table table)
        {
            //foreach(Column _col in SqlAccess.GetPrimaryKeysStatic(
            foreach (Column _column in table.Columns)
            {
                stream.WriteLine("\t\t[DataMember]");
                stream.WriteLine("\t\t[DataField(\"" + _column.Name + "\")]");
                switch (_column.Type)
                {
                    case "string":
                        stream.WriteLine("\t\t[MaxLengthString(" + _column.Length + "]");
                        break;
                    case "int":
                        stream.WriteLine("\t\t[Numeric]");
                        break;
                    case "decimal":
                        stream.WriteLine("\t\t[Numeric]");
                        break;
                    default:
                        break;
                }
                stream.WriteLine(string.Concat("\t\tpublic ", SqlAccess.GetCsType(_column), " ", _column.Name, "{get; set;}"));
            }
        }

        internal static void CreateInterface(Table table, string ProjectName, string path)
        {
            StringBuilder strBuilder = new StringBuilder();
            strBuilder.Append("I");
            strBuilder.Append(table.Name);
            strBuilder.Append("Service");
            string interfacename = strBuilder.ToString();

            string file = string.Concat(strBuilder.ToString(), ".cs");
            path = Path.Combine(path, ProjectName);
            string folderPath = Path.Combine(path, "Services");
            Directory.CreateDirectory(folderPath);

            using (StreamWriter streamWriter = new StreamWriter(Path.Combine(folderPath, file)))
            {
                //Definiendo librerias de dependecia.
                streamWriter.WriteLine("using System;");
                streamWriter.WriteLine("using System.Collections.Generic;");
                streamWriter.WriteLine("using System.ServiceModel;");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("using SIMA.Entities;");
                streamWriter.WriteLine("using SIMA.Core.Enums;");
                streamWriter.WriteLine("using SIMA.Core.Security;");
                streamWriter.WriteLine("");

                //Definiendo el namespace
                strBuilder.Remove(0, strBuilder.Length);
                strBuilder.Append("namespace ");
                strBuilder.Append(ProjectName);
                strBuilder.Append(".");
                strBuilder.Append("Services");
                streamWriter.WriteLine(strBuilder.ToString());
                streamWriter.WriteLine("{");

                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t[ServiceContract]");
                strBuilder.Remove(0, strBuilder.Length);
                strBuilder.Append("\tpublic interface ");
                strBuilder.Append(interfacename);
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("\t{");

                #region Get all code

                strBuilder.Append("\t\t#region Get all ");
                strBuilder.Append(table.Name);
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);

                streamWriter.WriteLine("\t\t[OperationContract]");
                strBuilder.Append("\t\tList<");
                strBuilder.Append(table.Name);
                strBuilder.Append("> ");
                strBuilder.Append("GetAll");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile)");
                strBuilder.Append(";");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);

                streamWriter.WriteLine("");

                streamWriter.WriteLine("\t\t[OperationContract(AsyncPattern = true)]");
                strBuilder.Append("\t\tIAsyncResult ");
                strBuilder.Append("BeginGetAll");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile, AsyncCallback callback, object state)");
                strBuilder.Append(";");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("");

                strBuilder.Append("\t\tList<");
                strBuilder.Append(table.Name);
                strBuilder.Append("> ");
                strBuilder.Append("EndGetAll");
                strBuilder.Append(table.Name);
                strBuilder.Append("(IAsyncResult asyncResult);");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("");

                streamWriter.WriteLine("\t\t#endregion");

                streamWriter.WriteLine("");

                #endregion

                #region Get filtered code

                strBuilder.Append("\t\t#region Get filtered ");
                strBuilder.Append(table.Name);
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);

                streamWriter.WriteLine("\t\t[OperationContract]");
                strBuilder.Append("\t\tList<");
                strBuilder.Append(table.Name);
                strBuilder.Append("> ");
                strBuilder.Append("GetFiltered");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile, FilterType filter)");
                strBuilder.Append(";");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("");

                streamWriter.WriteLine("\t\t[OperationContract(AsyncPattern = true)]");
                strBuilder.Append("\t\tIAsyncResult ");
                strBuilder.Append("BeginGetFiltered");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile, FilterType filter, AsyncCallback callback, object state)");
                strBuilder.Append(";");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("");

                strBuilder.Append("\t\tList<");
                strBuilder.Append(table.Name);
                strBuilder.Append("> ");
                strBuilder.Append("EndGetFiltered");
                strBuilder.Append(table.Name);
                strBuilder.Append("(IAsyncResult asyncResult)");
                strBuilder.Append(";");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("");

                streamWriter.WriteLine("\t\t#endregion");

                streamWriter.WriteLine("");

                #endregion

                #region New item code

                strBuilder.Append("\t\t#region New ");
                strBuilder.Append(table.Name);
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);

                streamWriter.WriteLine("\t\t[OperationContract]");
                strBuilder.Append("\t\tstring ");
                strBuilder.Append("Register");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile, ");
                strBuilder.Append(table.Name);
                strBuilder.Append(" newItem);");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("");

                streamWriter.WriteLine("\t\t[OperationContract(AsyncPattern = true)]");
                strBuilder.Append("\t\tIAsyncResult ");
                strBuilder.Append("BeginRegister");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile, ");//" FilterType filter, AsyncCallback callback, object state)");
                strBuilder.Append(table.Name);
                strBuilder.Append(" newItem, ");
                strBuilder.Append("AsyncCallback callback, object state);");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("");

                //streamWriter.WriteLine("\t\t[OperationContract]");
                strBuilder.Append("\t\tstring ");
                strBuilder.Append("EndRegister");
                strBuilder.Append(table.Name);
                strBuilder.Append("(IAsyncResult asyncResult);");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("");

                streamWriter.WriteLine("\t\t#endregion");

                streamWriter.WriteLine("");

                #endregion

                #region Update item code

                strBuilder.Append("\t\t#region Update ");
                strBuilder.Append(table.Name);
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);

                streamWriter.WriteLine("\t\t[OperationContract]");
                strBuilder.Append("\t\tstring ");
                strBuilder.Append("Update");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile, ");
                strBuilder.Append(table.Name);
                strBuilder.Append(" itemToUpdate, ");
                strBuilder.Append(table.Name);
                strBuilder.Append(" itemUpdated);");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("");

                streamWriter.WriteLine("\t\t[OperationContract(AsyncPattern = true)]");
                strBuilder.Append("\t\tIAsyncResult ");
                strBuilder.Append("BeginUpdate");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile, ");
                strBuilder.Append(table.Name);
                strBuilder.Append(" itemToUpdate, ");
                strBuilder.Append(table.Name);
                strBuilder.Append(" itemUpdated, ");
                strBuilder.Append("AsyncCallback callback, object state);");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("");

                //streamWriter.WriteLine("\t\t[OperationContract]");
                strBuilder.Append("\t\tstring ");
                strBuilder.Append("EndUpdate");
                strBuilder.Append(table.Name);
                strBuilder.Append("(IAsyncResult asyncResult);");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("");

                streamWriter.WriteLine("\t\t#endregion");

                streamWriter.WriteLine("");

                #endregion

                #region Delete item code

                strBuilder.Append("\t\t#region Delete ");
                strBuilder.Append(table.Name);
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);

                streamWriter.WriteLine("\t\t[OperationContract]");
                strBuilder.Append("\t\tstring ");
                strBuilder.Append("Delete");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile, ");
                strBuilder.Append(table.Name);
                strBuilder.Append(" dropItem);");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("");

                streamWriter.WriteLine("\t\t[OperationContract(AsyncPattern = true)]");
                strBuilder.Append("\t\tIAsyncResult ");
                strBuilder.Append("BeginDelete");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile, ");//" FilterType filter, AsyncCallback callback, object state)");
                strBuilder.Append(table.Name);
                strBuilder.Append(" dropItem, ");
                strBuilder.Append("AsyncCallback callback, object state);");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("");

                //streamWriter.WriteLine("\t\t[OperationContract]");
                strBuilder.Append("\t\tstring ");
                strBuilder.Append("EndDelete");
                strBuilder.Append(table.Name);
                strBuilder.Append("(IAsyncResult asyncResult);");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("");

                streamWriter.WriteLine("\t\t#endregion");

                streamWriter.WriteLine("");

                #endregion

                streamWriter.WriteLine("\t}");

                streamWriter.WriteLine("}");
                streamWriter.WriteLine("");
            }
        }

        internal static void CreateService(Table table, string ProjectName, string path)
        {
            StringBuilder strBuilder = new StringBuilder();
            strBuilder.Append("I");
            strBuilder.Append(table.Name);
            strBuilder.Append("Service");
            string interfacename = strBuilder.ToString();

            strBuilder.Remove(0, strBuilder.Length);
            strBuilder.Append(table.Name);
            strBuilder.Append("Service");
            string servicename = strBuilder.ToString();
            strBuilder.Remove(0, strBuilder.Length);

            string file = string.Concat(servicename, ".cs");
            path = Path.Combine(path, ProjectName);
            string folderPath = Path.Combine(path, "Services");
            Directory.CreateDirectory(folderPath);

            using (StreamWriter streamWriter = new StreamWriter(Path.Combine(folderPath, file)))
            {


                strBuilder.Append(table.Name);
                strBuilder.Append("AsyncResult");
                string asyncClass = strBuilder.ToString();
                strBuilder.Remove(0, strBuilder.Length);

                #region Declarando las librerias

                streamWriter.WriteLine("using System;");
                streamWriter.WriteLine("using System.Collections.Generic;");
                streamWriter.WriteLine("using System.ServiceModel;");
                streamWriter.WriteLine("using System.Threading;");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("using SIMA.Entities;");
                streamWriter.WriteLine("using SIMA.Core.Data.Collection;");
                streamWriter.WriteLine("using SIMA.Core.Data.Access;");
                streamWriter.WriteLine("using SIMA.Core.Enums;");
                streamWriter.WriteLine("using SIMA.Core.EventArgs;");
                streamWriter.WriteLine("using SIMA.Core.Security;");
                streamWriter.WriteLine("");

                #endregion

                #region Declarando el namespace

                strBuilder.Remove(0, strBuilder.Length);
                strBuilder.Append("namespace ");
                strBuilder.Append(ProjectName);
                strBuilder.Append(".");
                strBuilder.Append("Services");
                streamWriter.WriteLine(strBuilder.ToString());
                streamWriter.WriteLine("{");
                strBuilder.Remove(0, strBuilder.Length);

                #endregion

                #region Declarando header de clase

                streamWriter.WriteLine("");
                strBuilder.Append("\tpublic class ");
                strBuilder.Append(servicename);
                strBuilder.Append(" : ");
                strBuilder.Append(interfacename);
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("\t{");

                #endregion

                #region Declarando atributos

                streamWriter.WriteLine("\t\t#region Fields");
                streamWriter.WriteLine("");
                strBuilder.Append("\t\tprivate SmartContainer<");
                strBuilder.Append(table.Name);
                strBuilder.Append("> dataAccessSmart;");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("\t\tprivate FailedEventArgs onFailed;");
                streamWriter.WriteLine("\t\tprivate InsertedEventArgs onInserted;");
                streamWriter.WriteLine("\t\tprivate UpdatedEventArgs onUpdated;");
                streamWriter.WriteLine("\t\tprivate DeletedEventArgs onDeleted;");
                streamWriter.WriteLine("\t\tprivate static Semaphore ResourceLock;");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\t#endregion");
                streamWriter.WriteLine("");

                #endregion

                #region Declarando constructor

                streamWriter.WriteLine("\t\t#region Constructor");
                streamWriter.WriteLine("");
                strBuilder.Append("\t\tpublic ");
                strBuilder.Append(servicename);
                strBuilder.Append("()");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tDataAccess.SetConnection(SIMA.Core.Enums.AccessType.FromString, \"Data Source=.;Initial Catalog=SIMA;Integrated Security=True\");");
                streamWriter.WriteLine("\t\t\tResourceLock = new Semaphore(0, 2);");
                strBuilder.Append("\t\t\tdataAccessSmart = new SmartContainer<");
                strBuilder.Append(table.Name);
                strBuilder.Append(">(false,true);");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("\t\t\tdataAccessSmart.Inserted += new EventHandler<InsertedEventArgs>(dataAccessSmart_Inserted);");
                streamWriter.WriteLine("\t\t\tdataAccessSmart.Failed += new EventHandler<FailedEventArgs>(dataAccessSmart_Failed);");
                streamWriter.WriteLine("\t\t\tdataAccessSmart.Updated += new EventHandler<UpdatedEventArgs>(dataAccessSmart_Updated);");
                streamWriter.WriteLine("\t\t\tdataAccessSmart.Deleted += new EventHandler<DeletedEventArgs>(dataAccessSmart_Deleted);");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\t#endregion");
                streamWriter.WriteLine("");

                #endregion

                #region Implementando eventos del SmartContainer

                streamWriter.WriteLine("\t\t#region Implementacion de eventos del SmartContainer");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\tprivate void dataAccessSmart_Inserted(object sender, InsertedEventArgs e)");
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tonInserted = e;");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine("");

                streamWriter.WriteLine("\t\tprivate void dataAccessSmart_Updated(object sender, UpdatedEventArgs e)");
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tonUpdated = e;");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine("");

                streamWriter.WriteLine("\t\tprivate void dataAccessSmart_Deleted(object sender, DeletedEventArgs e)");
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tonDeleted = e;");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine("");

                streamWriter.WriteLine("\t\tprivate void dataAccessSmart_Failed(object sender, FailedEventArgs e)");
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tonFailed = e;");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine("");

                streamWriter.WriteLine("\t\t#endregion");

                #endregion

                #region Implementando la interfaz de servicio

                streamWriter.WriteLine("\t\t#region Implementando la interfaz de servicio");
                streamWriter.WriteLine("");

                #region Get All

                #region Get All Table

                strBuilder.Append("\t\tpublic List<");
                strBuilder.Append(table.Name);
                strBuilder.Append("> ");
                strBuilder.Append("GetAll");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile)");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tSecurityProgram.PcProfile = securityProfile;");
                streamWriter.WriteLine("\t\t\tdataAccessSmart.SelectAll();");
                streamWriter.WriteLine("\t\t\treturn dataAccessSmart.ToList();");
                streamWriter.WriteLine("\t\t}");
                
                #endregion

                streamWriter.WriteLine();

                #region Begin Get All

                strBuilder.Append("\t\tpublic IAsyncResult ");
                strBuilder.Append("BeginGetAll");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile, AsyncCallback callback, object state)");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("\t\t{");
                strBuilder.Append("\t\t\t");
                strBuilder.Append(asyncClass);
                strBuilder.Append(" asyncResult = new ");
                strBuilder.Append(asyncClass);
                strBuilder.Append("(securityProfile, callback, state);");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                strBuilder.Append("\t\t\tThreadPool.QueueUserWorkItem(new WaitCallback((GetAll");
                strBuilder.Append(table.Name);
                strBuilder.Append("Callback)), asyncResult);");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("\t\t\treturn asyncResult;");
                streamWriter.WriteLine("\t\t}");

                #endregion                

                streamWriter.WriteLine();

                #region Get All Callback

                strBuilder.Append("\t\tprivate void GetAll");
                strBuilder.Append(table.Name);
                strBuilder.Append("Callback(object asyncResult)");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("\t\t{");
                strBuilder.Append("\t\t\t");
                strBuilder.Append(asyncClass);
                strBuilder.Append(" get");
                strBuilder.Append(asyncClass);
                strBuilder.Append(" = (");
                strBuilder.Append(asyncClass);
                strBuilder.Append(")asyncResult;");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("\t\t\ttry");
                streamWriter.WriteLine("\t\t\t{");
                strBuilder.Append("\t\t\t\tget");
                strBuilder.Append(asyncClass);
                strBuilder.Append(".CollectionResult = ");
                strBuilder.Append("GetAll");
                strBuilder.Append(table.Name);
                strBuilder.Append("(SecurityProgram.PcProfile);");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                strBuilder.Append("\t\t\t\tget");
                strBuilder.Append(asyncClass);
                strBuilder.Append(".ExceptionTrace = null;");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                strBuilder.Append("\t\t\t\tget");
                strBuilder.Append(asyncClass);
                strBuilder.Append(".MessageResult = string.Empty;");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("\t\t\t}");
                streamWriter.WriteLine("\t\t\tcatch(Exception ex)");
                streamWriter.WriteLine("\t\t\t{");
                strBuilder.Append("\t\t\t\tget");
                strBuilder.Append(asyncClass);
                strBuilder.Append(".CollectionResult = null;");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                strBuilder.Append("\t\t\t\tget");
                strBuilder.Append(asyncClass);
                strBuilder.Append(".ExceptionTrace = ex;");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                strBuilder.Append("\t\t\t\tget");
                strBuilder.Append(asyncClass);
                strBuilder.Append(".MessageResult = string.Empty;");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("\t\t\t}");
                streamWriter.WriteLine("\t\t\tfinally");
                streamWriter.WriteLine("\t\t\t{");
                strBuilder.Append("\t\t\t\tget");
                strBuilder.Append(asyncClass);
                strBuilder.Append(".OnCompleted();");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("\t\t\t}");
                streamWriter.WriteLine("\t\t}");

                #endregion

                streamWriter.WriteLine();

                #region End Get All

                strBuilder.Append("\t\tpublic List<");
                strBuilder.Append(table.Name);
                strBuilder.Append("> EndGetAll");
                strBuilder.Append(table.Name);
                strBuilder.Append("(IAsyncResult asyncResult)");
                streamWriter.WriteLine(strBuilder.ToString());
                streamWriter.WriteLine("\t\t{");
                strBuilder.Remove(0, strBuilder.Length);
                strBuilder.Append("\t\t\tList<");
                strBuilder.Append(table.Name);
                strBuilder.Append("> lista = null;");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Clear();
                strBuilder.Append("\t\t\tusing(");
                strBuilder.Append(table.Name);
                strBuilder.Append("AsyncResult get");
                strBuilder.Append(table.Name);
                strBuilder.Append("Result = asyncResult as ");
                strBuilder.Append(table.Name);
                strBuilder.Append("AsyncResult)");
                streamWriter.WriteLine(strBuilder.ToString());
                streamWriter.WriteLine("\t\t\t{");
                strBuilder.Clear();
                strBuilder.Append("\t\t\t\tget");
                strBuilder.Append(table.Name);
                strBuilder.Append("Result.AsyncWaitHandle.WaitOne();");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Clear();
                strBuilder.Append("\t\t\t\tlista = get");
                strBuilder.Append(table.Name);
                strBuilder.Append("Result.CollectionResult;");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Clear();
                streamWriter.WriteLine("\t\t\t}");
                streamWriter.WriteLine("\t\t\treturn lista;");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine();

                #endregion


                #endregion

                #region Get Filtered

                #region Get Filtered

                strBuilder.Append("\t\tpublic List<");
                strBuilder.Append(table.Name);
                strBuilder.Append("> ");
                strBuilder.Append("GetFiltered");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile, FilterType filter)");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Clear();
                strBuilder.Append("\t\t{");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Clear();

                strBuilder.Append("\t\t}");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Clear();

                #endregion

                #region Begin Get Filtered

                strBuilder.Append("\t\tpublic IAsyncResult ");
                strBuilder.Append("BeginGetFiltered");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile, FilterType filter, AsyncCallback callback, object state)");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Clear();
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t}");
                

                #endregion

                #region End Filtered

                strBuilder.Append("\t\tpublic List<");
                strBuilder.Append(table.Name);
                strBuilder.Append("> ");
                strBuilder.Append("EndGetFiltered");
                strBuilder.Append(table.Name);
                strBuilder.Append("(IAsyncResult asyncResult)");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Clear();
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t}");

                #endregion

                #endregion

                #region New

                strBuilder.Append("\t\tpublic string ");
                strBuilder.Append("Register");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile, ");
                strBuilder.Append(table.Name);
                strBuilder.Append(" newItem)");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Clear();
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine();

                strBuilder.Append("\t\tpublic IAsyncResult ");
                strBuilder.Append("BeginRegister");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile, ");//" FilterType filter, AsyncCallback callback, object state)");
                strBuilder.Append(table.Name);
                strBuilder.Append(" newItem, ");
                strBuilder.Append("AsyncCallback callback, object state)");
                streamWriter.WriteLine(strBuilder.ToString());
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t}");
                strBuilder.Clear();
                streamWriter.WriteLine("");

                strBuilder.Append("\t\tpublic string ");
                strBuilder.Append("EndRegister");
                strBuilder.Append(table.Name);
                strBuilder.Append("(IAsyncResult asyncResult)");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine("");

                #endregion

                #region Update

                strBuilder.Append("\t\tpublic string ");
                strBuilder.Append("Update");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile, ");
                strBuilder.Append(table.Name);
                strBuilder.Append(" itemToUpdate, ");
                strBuilder.Append(table.Name);
                strBuilder.Append(" itemUpdated)");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Clear();
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t}");

                strBuilder.Append("\t\tpublic IAsyncResult ");
                strBuilder.Append("BeginUpdate");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile, ");
                strBuilder.Append(table.Name);
                strBuilder.Append(" itemToUpdate, ");
                strBuilder.Append(table.Name);
                strBuilder.Append(" itemUpdated, ");
                strBuilder.Append("AsyncCallback callback, object state)");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine();

                strBuilder.Append("\t\tpublic string ");
                strBuilder.Append("EndUpdate");
                strBuilder.Append(table.Name);
                strBuilder.Append("(IAsyncResult asyncResult)");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t}");

                #endregion

                #region Delete

                strBuilder.Append("\t\tpublic string ");
                strBuilder.Append("Delete");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile, ");
                strBuilder.Append(table.Name);
                strBuilder.Append(" dropItem)");
                streamWriter.WriteLine(strBuilder.ToString());                
                strBuilder.Clear();
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine();

                strBuilder.Append("\t\tpublic IAsyncResult ");
                strBuilder.Append("BeginDelete");
                strBuilder.Append(table.Name);
                strBuilder.Append("(Profile securityProfile, ");//" FilterType filter, AsyncCallback callback, object state)");
                strBuilder.Append(table.Name);
                strBuilder.Append(" dropItem, ");
                strBuilder.Append("AsyncCallback callback, object state)");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Clear();
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine();

                //streamWriter.WriteLine("\t\t[OperationContract]");
                strBuilder.Append("\t\tpublic string ");
                strBuilder.Append("EndDelete");
                strBuilder.Append(table.Name);
                strBuilder.Append("(IAsyncResult asyncResult)");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Clear();
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine();

                #endregion

                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\t#endregion");

                #endregion

                #region Close class

                streamWriter.WriteLine("\t}");

                #endregion

                #region Close namespace

                streamWriter.WriteLine("}");

                #endregion

            }
        }

        internal static void CreateAsyncResult(Table table, string ProjectName, string path)
        {
            StringBuilder strBuilder = new StringBuilder();
            strBuilder.Append("");
            strBuilder.Append(table.Name);
            strBuilder.Append("AsyncResult");

            string asyncclassName = strBuilder.ToString();
            string file = string.Concat(strBuilder.ToString(), ".cs");

            path = Path.Combine(path, ProjectName);
            string folderPath = Path.Combine(path, "Services");
            Directory.CreateDirectory(folderPath);

            using (StreamWriter streamWriter = new StreamWriter(Path.Combine(folderPath, file)))
            {
                #region Declarando las librerias

                streamWriter.WriteLine("using System;");
                streamWriter.WriteLine("using System.Collections.Generic;");
                streamWriter.WriteLine("using System.Text;");
                streamWriter.WriteLine("using System.Threading;");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("using SIMA.Entities;");
                streamWriter.WriteLine("using SIMA.Core.Security;");
                streamWriter.WriteLine("");

                #endregion

                #region Declarando el namespace

                strBuilder.Remove(0, strBuilder.Length);
                strBuilder.Append("namespace ");
                strBuilder.Append(ProjectName);
                strBuilder.Append(".");
                strBuilder.Append("Services");
                streamWriter.WriteLine(strBuilder.ToString());
                streamWriter.WriteLine("{");
                strBuilder.Remove(0, strBuilder.Length);

                #endregion

                #region Declarando clase

                streamWriter.WriteLine("");
                strBuilder.Append("\tpublic class ");
                strBuilder.Append(asyncclassName);
                strBuilder.Append(" : AsyncResult");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("\t{");


                #endregion

                #region Declarando Atributos

                streamWriter.WriteLine("\t\t#region Fields");
                streamWriter.WriteLine("");
                strBuilder.Append("\t\tprivate List<");
                strBuilder.Append(table.Name);
                strBuilder.Append("> collectionResult;");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("\t\tprivate Exception exceptionTrace;");
                streamWriter.WriteLine("\t\tprivate string messageResult;");
                streamWriter.WriteLine("\t\tprivate Profile profile;");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\t#endregion");
                streamWriter.WriteLine("");

                #endregion

                #region Declarando Propiedades

                streamWriter.WriteLine("\t\t#region Properties");
                streamWriter.WriteLine("");
                strBuilder.Append("\t\tpublic List<");
                strBuilder.Append(table.Name);
                strBuilder.Append("> CollectionResult");
                streamWriter.WriteLine(strBuilder.ToString());
                strBuilder.Remove(0, strBuilder.Length);
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tget { return collectionResult; }");
                streamWriter.WriteLine("\t\t\tset { collectionResult = value; }");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\tpublic Exception ExceptionTrace");
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tget { return exceptionTrace; }");
                streamWriter.WriteLine("\t\t\tset { exceptionTrace = value; }");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\tpublic string MessageResult");
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tget { return messageResult; }");
                streamWriter.WriteLine("\t\t\tset { messageResult = value; }");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\tpublic Profile Profile");
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tget { return profile; }");
                streamWriter.WriteLine("\t\t\tset { profile = value; }");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\t#endregion");
                streamWriter.WriteLine("");

                #endregion

                #region Declarando Constructor

                streamWriter.WriteLine("\t\t#region Constructor");
                streamWriter.WriteLine("");
                strBuilder.Append("\t\tpublic ");
                strBuilder.Append(asyncclassName);
                strBuilder.Append("(Profile profile, AsyncCallback callback, object state) : base(profile, callback, state)");
                streamWriter.WriteLine(strBuilder.ToString());
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\t#endregion");

                #endregion

                #region Cerrando Clase

                streamWriter.WriteLine("\t}");

                #endregion

                #region Cerrando Namespace

                streamWriter.WriteLine("}");

                #endregion
            }
        }

        internal static void CreateBaseAsyncResult(string ProjectName, string path)
        {
            StringBuilder strBuilder = new StringBuilder();

            string file = string.Concat("BaseAsyncResult", ".cs");
            path = Path.Combine(path, ProjectName);
            string folderPath = Path.Combine(path, "Services");
            Directory.CreateDirectory(folderPath);

            using (StreamWriter streamWriter = new StreamWriter(Path.Combine(folderPath, file)))
            {
                #region Declarando las librerias
                streamWriter.WriteLine("using System;");
                streamWriter.WriteLine("using System.Collections.Generic;");
                streamWriter.WriteLine("using System.ServiceModel;");
                streamWriter.WriteLine("using System.Threading;");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("using SIMA.Entities;");
                streamWriter.WriteLine("using SIMA.Core.Data.Collection;");
                streamWriter.WriteLine("using SIMA.Core.Data.Access;");
                streamWriter.WriteLine("using SIMA.Core.Enums;");
                streamWriter.WriteLine("using SIMA.Core.EventArgs;");
                streamWriter.WriteLine("using SIMA.Core.Security;");
                streamWriter.WriteLine("");
                #endregion

                #region Declarando el namespace

                strBuilder.Remove(0, strBuilder.Length);
                strBuilder.Append("namespace ");
                strBuilder.Append(ProjectName);
                strBuilder.Append(".");
                strBuilder.Append("Services");
                streamWriter.WriteLine(strBuilder.ToString());
                streamWriter.WriteLine("{");
                strBuilder.Remove(0, strBuilder.Length);

                #endregion

                #region Declarando header de clase

                streamWriter.WriteLine("");
                streamWriter.WriteLine("\tpublic class AsyncResult : IAsyncResult, IDisposable");
                streamWriter.WriteLine("\t{");

                #endregion

                #region Declarando atributos

                streamWriter.WriteLine("\t\t#region Fields");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\tprivate AsyncCallback m_AsyncCallback;");
                streamWriter.WriteLine("\t\tprivate object m_State;");
                streamWriter.WriteLine("\t\tprivate ManualResetEvent m_ManualResentEvent;");
                streamWriter.WriteLine("\t\tprivate Profile profile;");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\t#endregion");
                streamWriter.WriteLine("");

                #endregion

                #region Declarando constructor

                streamWriter.WriteLine("\t\t#region Constructor");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\tpublic AsyncResult(Profile profile, AsyncCallback callback, object state) ");
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tthis.m_AsyncCallback = callback;");
                streamWriter.WriteLine("\t\t\tthis.m_State = state;");
                streamWriter.WriteLine("\t\t\tthis.m_ManualResentEvent = new ManualResetEvent(false);");
                streamWriter.WriteLine("\t\t\tthis.profile = profile;");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\t#endregion");
                streamWriter.WriteLine("");

                #endregion

                #region Declarando Metodos

                streamWriter.WriteLine("\t\t#region Miembros de IAsyncResult");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\tpublic object AsyncState");
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tget");
                streamWriter.WriteLine("\t\t\t{");
                streamWriter.WriteLine("\t\t\t\treturn m_State;");
                streamWriter.WriteLine("\t\t\t}");
                streamWriter.WriteLine("\t\t}");

                streamWriter.WriteLine("\t\tpublic System.Threading.WaitHandle AsyncWaitHandle");
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tget");
                streamWriter.WriteLine("\t\t\t{");
                streamWriter.WriteLine("\t\t\t\treturn m_ManualResentEvent;");
                streamWriter.WriteLine("\t\t\t}");
                streamWriter.WriteLine("\t\t}");

                streamWriter.WriteLine("\t\tpublic bool CompletedSynchronously");
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tget");
                streamWriter.WriteLine("\t\t\t{");
                streamWriter.WriteLine("\t\t\t\treturn false;");
                streamWriter.WriteLine("\t\t\t}");
                streamWriter.WriteLine("\t\t}");

                streamWriter.WriteLine("\t\tpublic bool IsCompleted");
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tget");
                streamWriter.WriteLine("\t\t\t{");
                streamWriter.WriteLine("\t\t\t\treturn m_ManualResentEvent.WaitOne(0, false);");
                streamWriter.WriteLine("\t\t\t}");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine("\t\t#endregion");
                streamWriter.WriteLine("");

                streamWriter.WriteLine("\t\t#region Miembros de IDisposable");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\tprivate bool m_IsDisposed = false;");
                streamWriter.WriteLine("\t\tprivate event System.EventHandler m_Disposed;");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\t[System.ComponentModel.Browsable(false)]");

                streamWriter.WriteLine("\t\tpublic bool IsDisposed");
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tget");
                streamWriter.WriteLine("\t\t\t{");
                streamWriter.WriteLine("\t\t\t\treturn m_IsDisposed;");
                streamWriter.WriteLine("\t\t\t}");
                streamWriter.WriteLine("\t\t}");

                streamWriter.WriteLine("\t\tpublic event System.EventHandler Disposed");
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tadd");
                streamWriter.WriteLine("\t\t\t{");
                streamWriter.WriteLine("\t\t\t\tm_Disposed += value;");
                streamWriter.WriteLine("\t\t\t}");
                streamWriter.WriteLine("\t\t\tremove");
                streamWriter.WriteLine("\t\t\t{");
                streamWriter.WriteLine("\t\t\t\tm_Disposed -= value;");
                streamWriter.WriteLine("\t\t\t}");
                streamWriter.WriteLine("\t\t}");

                streamWriter.WriteLine("\t\tpublic void Dispose()");
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tif (!m_IsDisposed)");
                streamWriter.WriteLine("\t\t\t{");
                streamWriter.WriteLine("\t\t\t\tthis.Dispose(true);");
                streamWriter.WriteLine("\t\t\t\tSystem.GC.SuppressFinalize(this);");
                streamWriter.WriteLine("\t\t\t}");
                streamWriter.WriteLine("\t\t}");

                streamWriter.WriteLine("\t\tpublic void Dispose(bool disposing)");
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\ttry");
                streamWriter.WriteLine("\t\t\t{");
                streamWriter.WriteLine("\t\t\t\tm_ManualResentEvent.Close();");
                streamWriter.WriteLine("\t\t\t\tm_ManualResentEvent = null;");
                streamWriter.WriteLine("\t\t\t\tm_State = null;");
                streamWriter.WriteLine("\t\t\t\tm_AsyncCallback = null;");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\t\t\tSystem.EventHandler handler = m_Disposed;");
                streamWriter.WriteLine("\t\t\t\tif (handler != null)");
                streamWriter.WriteLine("\t\t\t\t{");
                streamWriter.WriteLine("\t\t\t\t\thandler(this, System.EventArgs.Empty);");
                streamWriter.WriteLine("\t\t\t\t\thandler = null;");
                streamWriter.WriteLine("\t\t\t\t}");
                streamWriter.WriteLine("\t\t\t}");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\t\tfinally");
                streamWriter.WriteLine("\t\t\t{");
                streamWriter.WriteLine("\t\t\t\tm_IsDisposed = true;");
                streamWriter.WriteLine("\t\t\t}");
                streamWriter.WriteLine("\t\t}");

                streamWriter.WriteLine("\t\tprotected void CheckDisposed()");
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tif (m_IsDisposed)");
                streamWriter.WriteLine("\t\t\t{");
                streamWriter.WriteLine("\t\t\t\tstring typeName = GetType().FullName;");
                streamWriter.WriteLine("");
                streamWriter.WriteLine("\t\t\t\tthrow new System.ObjectDisposedException(typeName,String.Format(System.Globalization.CultureInfo.InvariantCulture,\"Cannot access a disposed {0}.\",typeName));");
                streamWriter.WriteLine("\t\t\t}");
                streamWriter.WriteLine("\t\t}");

                streamWriter.WriteLine("\t\t#endregion");
                streamWriter.WriteLine("");

                streamWriter.WriteLine("\t\tpublic virtual void OnCompleted()");
                streamWriter.WriteLine("\t\t{");
                streamWriter.WriteLine("\t\t\tm_ManualResentEvent.Set();");
                streamWriter.WriteLine("\t\t\tif (m_AsyncCallback != null)");
                streamWriter.WriteLine("\t\t\t{");
                streamWriter.WriteLine("\t\t\t\tm_AsyncCallback(this);");
                streamWriter.WriteLine("\t\t\t}");
                streamWriter.WriteLine("\t\t}");
                streamWriter.WriteLine("\t}");

                #endregion

                streamWriter.WriteLine("}");
            }

        }
    }
}
